package creator.service;

import com.appleyk.core.model.LicenseCreatorManager;
import com.appleyk.core.model.LicenseCreatorParam;
import com.appleyk.core.model.LicenseResult;
import com.appleyk.core.utils.DateUtils;

import java.text.MessageFormat;


/**
 * @Author: WangYao
 * @description: <p>证书生成接口实现</p>
 * @date: 2024-05-08 11:16
 */
public class LicenseCreatorService {
    /**
     * <p>生成证书</p>
     *
     * @param param 证书创建需要的参数对象
     * @return Map<String, Object>
     */
    public void generateLicense(LicenseCreatorParam param) {
        LicenseCreatorManager licenseCreator = new LicenseCreatorManager(param);
        LicenseResult licenseResult = licenseCreator.generateLicense();
        if (licenseResult.getResult()) {
            String message = MessageFormat.format("证书生成成功，证书有效期：{0} - {1}",
                    DateUtils.date2Str(param.getIssuedTime()), DateUtils.date2Str(param.getExpiryTime()));
            System.out.println("message = " + message);
        } else {
            System.out.println("证书文件生成失败！原因： " + licenseResult.getException().getMessage());
        }
    }


}
